home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / util / cdity / IFX.lha / IFX / AmigaE / ifx.e < prev    next >
Text File  |  1998-01-02  |  36KB  |  1,577 lines

  1. ->
  2. -> IFX
  3. ->
  4. -> © by Dobes Vandermeer, 1997
  5. ->
  6. -> Events daemon
  7. ->
  8.  
  9. -> Standard modules
  10. MODULE 'dos/dos',          'dos/dosextens',  'dos/dostags'
  11. MODULE 'exec/ports',       'exec/libraries', 
  12.       'exec/tasks',        'exec/nodes',     'exec/io',
  13.       'exec/interrupts',      'exec/semaphores',   'exec/memory'
  14. MODULE 'intuition/intuition'
  15. MODULE 'utility'
  16. MODULE 'libraries/commodities'
  17. MODULE 'timer'
  18. MODULE 'layers',           'graphics/clip'
  19. MODULE 'devices/input',       'devices/inputevent', 'devices/timer'
  20. MODULE 'workbench/startup',      'workbench/workbench'
  21. MODULE 'icon'
  22.  
  23. -> Special modules
  24. MODULE '*modules/action',     '*modules/ifx'
  25. MODULE '*patch'
  26. MODULE '*input/inputhandler'
  27. MODULE 'tools/cli'
  28. MODULE 'other/ecodex',        'other/split'
  29. MODULE 'fabio/rxobj_oo'
  30. MODULE 'fabio/cxobj_oo'
  31. MODULE 'tools/sound'
  32. MODULE 'amigalib/tasks'
  33. MODULE 'dos/dostags'
  34. MODULE '*speak/speak'
  35. MODULE 'tools/detatch'
  36.  
  37.  
  38. ->
  39. -> CONSTANTS
  40. ->
  41.  
  42. CONST IFX_VERSION=2, IFX_REVISION=5
  43.  
  44. CONST NAMESIZE=256
  45.  
  46. ->
  47. -> Global objects
  48. ->
  49.  
  50.    -> Ports and lists
  51. DEF rx:PTR TO rxobj
  52. DEF cx:PTR TO cxobj
  53. DEF mp:PTR TO mp  
  54. DEF ids:PTR TO ifx_id
  55. DEF tasks:PTR TO ifx_task
  56.  
  57.    -> Input Handler
  58. DEF inputhandler:PTR TO inputhandler
  59.    
  60.    -> Global flags
  61. DEF enabled, on_hour, do_chime, program_done
  62.  
  63.    -> Sounds
  64. DEF sounds:PTR TO LONG, curr_snd
  65.  
  66.    -> Signals
  67. DEF sigs:LONG, soundsigs:LONG
  68.  
  69.    -> Current directory
  70. DEF currentdir:LONG, olddir:LONG
  71.  
  72.    -> Patches
  73. DEF p_ow:PTR TO patch, p_owt:PTR TO patch, p_cw:PTR TO patch,
  74.    p_os:PTR TO patch, p_ost:PTR TO patch, p_cs:PTR TO patch,
  75.    p_db:PTR TO patch, p_msz:PTR TO patch
  76.  
  77.    -> Semaphore
  78. DEF ids_sem:PTR TO ss
  79.  
  80. ->
  81. -> MAIN
  82. ->
  83.  
  84. PROC main() HANDLE
  85.    -> Error messages
  86.    DEF err:PTR TO CHAR, more:PTR TO CHAR
  87.    
  88.    -> Signal processing
  89.    DEF gotsigs
  90.    
  91.    -> Message port
  92.    DEF msg:PTR TO ifx_msg
  93.    
  94.    -> Misc.
  95.    DEF temp
  96.  
  97.    -> Clock chimes
  98.    DEF timerio:PTR TO timerequest, timermp:PTR TO mp
  99.  
  100.    -> Detatch!
  101.    detatch('IFXII')
  102.  
  103.    ->
  104.    -> Initialize global variables
  105.    ->
  106.    -> This should be done FIRST to avoid errors!
  107.    ->
  108.    
  109.    ids := NIL
  110.    sigs := soundsigs := NIL
  111.    enabled := 1      -> We are active by DEFault
  112.    NEW sounds[2]
  113.    currentdir := olddir := NIL
  114.    curr_snd := 1
  115.    
  116.    ->
  117.    -> Only add the port if it isn't already added
  118.    ->
  119.    
  120.    ->>>
  121.    ->>>>>>> FORBID
  122.    Forbid()
  123.    IF mp := FindPort('IFX')
  124.       ->
  125.       -> If it is, tell us to QUIT.
  126.       ->
  127.       
  128.       ->
  129.       -> We'll send a EXEC message
  130.       ->
  131.       
  132.       NEW msg
  133.       msg.cmd := IFX_QUIT
  134.       msg.length := SIZEOF ifx_msg
  135.       PutMsg(mp, msg)
  136.          
  137.       ->
  138.       -> Wait long enough for (the other) IFX to quit.
  139.       ->
  140.       
  141.       Delay(50)
  142.       
  143.       ->
  144.       -> De-allocate the msg
  145.       ->
  146.       
  147.       END msg
  148.       msg := NIL
  149.       mp := NIL
  150.    ENDIF
  151.  
  152.    ->
  153.    -> Prepare exec mp (NEEDED by patches)
  154.    ->
  155.  
  156.    mp := CreateMsgPort()
  157.    IF mp=NIL
  158.       Permit()
  159.       Throw("INIT", "MP")
  160.    ENDIF
  161.    mp.ln.pri := 50
  162.    mp.ln.name:= 'IFX'
  163.    sigs := sigs OR Shl(1, mp.sigbit)
  164.    AddPort(mp)
  165.    
  166.    ->>>
  167.    ->>>>>>> PERMIT
  168.    Permit()
  169.       ->->WriteF('mp: \h (\h)\n', sigs, Shl(1, mp.sigbit))
  170.    
  171.    ->>
  172.    ->>>> LIBRARIES & DEVICES
  173.    ->>
  174.  
  175.    ->
  176.    -> Open Layers Library
  177.    ->
  178.    
  179.    layersbase := OpenLibrary('layers.library', 36)
  180.    IF layersbase=NIL THEN Throw("INIT", "LAYR")
  181.    
  182.    ->
  183.    -> Open Utility Library
  184.    ->
  185.    
  186.    utilitybase := OpenLibrary('utility.library', 36)
  187.    IF utilitybase=NIL THEN Throw("INIT", "UTIL")
  188.    
  189.    ->
  190.    -> Open input.device
  191.    ->
  192.    
  193.    NEW inputhandler.init({inputhandlerfunc}, NIL, 25, 'IFX Input Handler')
  194.       
  195.    ->
  196.    -> Open timer.device
  197.    ->
  198.    
  199.    timermp := CreateMsgPort()
  200.    IF timermp=NIL THEN Throw("INIT", "TiMP")
  201.       
  202.    timerio := CreateIORequest(timermp, SIZEOF timerequest)
  203.    IF timerio=NIL THEN Throw("INIT", "TiIO")
  204.       
  205.    IF OpenDevice('timer.device', UNIT_WAITUNTIL, timerio, NIL) THEN Throw("INIT", "TiOp")
  206.    timerbase := timerio.io.device
  207.    timerio.io.mn.ln.type := NIL        -> This should prevent crashes
  208.    sigs := sigs OR Shl(1, timermp.sigbit)
  209.       ->->WriteF('timer: \h (\h)\n', sigs, Shl(1, timermp.sigbit))
  210.  
  211.    ->
  212.    -> Get command line settings
  213.    ->
  214.    
  215.    do_wbargs()
  216.    
  217.    -> 
  218.    -> Load configuration data
  219.    ->
  220.    
  221.    load_config('S:IFX.ids')
  222.  
  223.    ->
  224.    -> Prepare patches
  225.    ->
  226.    
  227.    NEW p_ow.init( intuitionbase, -204, {new_ow},  TRUE)
  228.    NEW p_owt.init(intuitionbase, -606, {new_owt}, TRUE)
  229.    NEW p_cw.init( intuitionbase, -72,  {new_cw},  TRUE)
  230.    NEW p_os.init( intuitionbase, -198, {new_os},  TRUE)
  231.    NEW p_ost.init(intuitionbase, -612, {new_ost}, TRUE)
  232.    NEW p_cs.init( intuitionbase, -66,  {new_cs},  TRUE)
  233.    NEW p_db.init( intuitionbase, -96,  {new_db},  TRUE)
  234.    NEW p_msz.init(layersbase,    -180, {new_msz}, TRUE)
  235.  
  236.    ->>
  237.    ->>>> FORBID
  238.    Forbid()
  239.  
  240.    ->
  241.    -> Install patches
  242.    ->
  243.  
  244.    p_ow.install()
  245.    p_owt.install()
  246.    p_cw.install()
  247.    p_os.install()
  248.    p_ost.install()
  249.    p_cs.install()
  250.    p_db.install()
  251.    p_msz.install()
  252.  
  253.    ->
  254.    -> Set up first timer event
  255.    ->
  256.    -> The timer.device was opened earlier.
  257.    ->
  258.    
  259.    settimer(timerio)
  260.  
  261.    Permit()
  262.    ->>>> PERMIT
  263.    ->>
  264.    
  265.    ->
  266.    -> Install input handler
  267.    ->
  268.    -> The input.device was opened earlier
  269.    ->
  270.    
  271.    inputhandler.install()
  272.    
  273.    ->
  274.    -> Prepare commodities object
  275.    ->
  276.    
  277.    NEW cx.cxobj()
  278.    cx.create('IFX', 'IFX II  © by Dobes Vandermeer', 'Input effects (FX) Daemon')
  279.    sigs := sigs OR cx.signal()
  280.       ->->WriteF('cx: \h (\h)\n', sigs, cx.signal())
  281.    
  282.    ->
  283.    -> Prepare AREXX object
  284.    ->
  285.    
  286.    NEW rx.rxobj('PLAY')
  287.    sigs := sigs OR rx.signal()
  288.    
  289.    ->
  290.    -> Prepare Semaphore
  291.    ->
  292.    NEW ids_sem
  293.    InitSemaphore(ids_sem)
  294.    
  295.    ->
  296.    -> Break handling
  297.    ->
  298.    sigs := sigs OR SIGBREAKF_CTRL_C
  299.       
  300.    -> Main Loop
  301.    program_done := FALSE
  302.    gotsigs := CheckSignal(sigs)
  303.    WHILE program_done=FALSE
  304.       ->
  305.       -> Check for a timer event
  306.       ->
  307.       
  308.       IF (gotsigs AND Shl(1, timermp.sigbit))<>NIL
  309.          WaitIO(timerio)               -> Get the event
  310.          IF on_hour
  311.             do_effect('hourly_chime')
  312.          ELSE
  313.             do_effect('quarterly_chime')
  314.          ENDIF
  315.          settimer(timerio)
  316.       ENDIF
  317.       
  318.       ->
  319.       -> Check for a message (probably from a patch)
  320.       ->
  321.       
  322.       IF (gotsigs AND Shl(1, mp.sigbit))<>NIL
  323.          WHILE (msg := GetMsg(mp))<>NIL
  324.             temp := msg.cmd
  325.             SELECT temp
  326.                CASE -1     -> One of our patches
  327.                   IF checktask(msg.data)=FALSE
  328.                      do_effect(msg.id)
  329.                   ENDIF
  330.                   FreeMem(msg, msg.length)   -> Free it for them
  331.                   
  332.                CASE IFX_ID
  333.                   IF msg.id THEN do_effect(msg.id)
  334.                   IF msg.replyport THEN ReplyMsg(msg)
  335.                
  336.                CASE IFX_EDIT_IDS
  337.                   msg.data := ids
  338.                   IF msg.replyport THEN ReplyMsg(msg)
  339.                
  340.                CASE IFX_EDIT_TASKS
  341.                   msg.data := tasks
  342.                   IF msg.replyport THEN ReplyMsg(msg)
  343.                
  344.                CASE IFX_EDIT_SEM
  345.                   msg.data := ids_sem
  346.                   IF msg.replyport THEN ReplyMsg(msg)
  347.  
  348.                CASE IFX_ACTION
  349.                   IF msg.data      THEN do_action(msg.data)
  350.                   IF msg.replyport THEN ReplyMsg(msg)
  351.                
  352.                CASE IFX_EFFECT
  353.                   IF msg.data      THEN do_effect(msg.data)
  354.                   IF msg.replyport THEN ReplyMsg(msg)
  355.                
  356.                CASE IFX_CHIMES
  357.                   IF msg.data
  358.                      do_chime := 1
  359.                   ELSE
  360.                      do_chime := 0
  361.                   ENDIF
  362.                   IF msg.replyport THEN ReplyMsg(msg)
  363.                
  364.                CASE IFX_PARSE
  365.                   IF msg.data
  366.                      ifx_parse(msg.data)
  367.                   ENDIF
  368.                   
  369.                CASE IFX_QUIT
  370.                   IF msg.replyport THEN ReplyMsg(msg)
  371.                   do_effect('ifx_kill')
  372.                   program_done := TRUE
  373.                                  
  374.                DEFAULT
  375.                   IF msg.replypor